/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.registration.gui.security;

import it.polimi.registration.business.security.boundary.UsersManager;
import it.polimi.registration.business.security.entity.Users;
import javax.ejb.EJB;
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;

/**
 *
 * @author miglie
 */
@Named
@RequestScoped
public class RegistrationBean {

    @EJB
    private UsersManager um;

    private Users users;

    public RegistrationBean() {
    }

    public Users getUsers() {
        if (users == null) {
            users = new Users();
        }
        return users;
    }

    public void setUsers(Users users) {
        this.users = users;
    }

    public String register() {
        if(!um.checkExistingUser(users.getEmail())){
            um.save(users);
            return "/index?faces-redirect=true";
        }
        else 
            return "/register?faces-redirect=true";
    }

}
